//
//  ReweetedView.swift
//  weibo
//
//  Created by 上官风雨 on 15/11/15.
//  Copyright © 2015年 上官风雨. All rights reserved.
//

import UIKit
import SnapKit

class ReweetedView: UIView {
    
    var bottomConsraints :Constraint?
    
    var reweentedStatus:Status?{
        
        didSet{
            
            self.bottomConsraints?.uninstall()
            reweentedLabel.text = reweentedStatus?.text
            
            if let imageurl = reweentedStatus?.imageURLs where imageurl.count > 0{
                
                pictureView.imageURLs = reweentedStatus?.imageURLs
                
                pictureView.hidden = false
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomConsraints =  make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                })
                
            } else{
                pictureView.hidden = true
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomConsraints =  make.bottom.equalTo(reweentedLabel.snp_bottom).offset(StatusCellMargin).constraint
                })
                
            }
            
            
        }
        
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.93, alpha: 1.0)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        addSubview(reweentedLabel)
        addSubview(pictureView)
        
        reweentedLabel.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.top.equalTo(self.snp_top)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
        
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.top.equalTo(reweentedLabel.snp_bottom).offset(StatusCellMargin)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            
         self.bottomConsraints =  make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
    }
    
    
    //懒加载控件
    lazy var reweentedLabel : UILabel = UILabel(title: "我是转发微博", size: 15, color: UIColor.darkGrayColor(), margin: StatusCellMargin)
    
    lazy var pictureView : StatusPictureView = StatusPictureView()
    
}
